home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / ZBRAK.PAS < prev    next >
Pascal/Delphi Source File  |  1991-04-29  |  767b  |  31 lines

  1. PROCEDURE zbrak(x1,x2: real; n: integer;
  2.       VAR xb1,xb2: glnbmax; VAR nb: integer);
  3. (* Programs using routine ZBRAK must externally define a function
  4. fx(x:real):real which is to be analyzed for roots. Also, the
  5. calling program must define type
  6. TYPE
  7.    glnbmax = ARRAY [1..nbmax] OF real;
  8. where nbmax is the maximum number to be required for 'nb'. *)
  9. LABEL 99;
  10. VAR
  11.    nbb,i: integer;
  12.    x,fp,fc,dx: real;
  13. BEGIN
  14.    nbb := nb;
  15.    nb := 0;
  16.    x := x1;
  17.    dx := (x2-x1)/n;
  18.    fp := fx(x);
  19.    FOR i := 1 TO n DO BEGIN
  20.       x := x+dx;
  21.       fc := fx(x);
  22.       IF ((fc*fp) < 0.0)  THEN BEGIN
  23.          nb := nb+1;
  24.          xb1[nb] := x-dx;
  25.          xb2[nb] := x
  26.       END;
  27.       fp := fc;
  28.       IF (nbb = nb) THEN GOTO 99;
  29.    END;
  30. 99:   END;
  31.